package com.e3.bill.client;

import com.e3.web.widget.client.BaseAction;
import com.e3.web.widget.client.MyActionFactory;

public class BillStateMachine {
	
	public static BillStateMachine INSTANCE = new BillStateMachine();

	public static BaseAction ACTION_NEW_REF = new BaseAction(BillMessages.INSTANCE.action_new_ref());
	
	public static BaseAction ACTION_GOTO_LIST = new BaseAction(BillMessages.INSTANCE.action_goto_list());

	public static BaseAction ACTION_ROW_ADD = new BaseAction(BillMessages.INSTANCE.action_row_add());
	
	public static BaseAction ACTION_ROW_DEL = new BaseAction(BillMessages.INSTANCE.action_row_delete());
	
	public static BaseAction ACTION_ROW_INSERT = new BaseAction(BillMessages.INSTANCE.action_row_insert());
	
	public static BaseAction ACTION_ROW_COPY = new BaseAction(BillMessages.INSTANCE.action_row_copy());
	
	public static BaseAction ACTION_ROW_PASTE = new BaseAction(BillMessages.INSTANCE.action_row_paste());
	
	public static BaseAction ACTION_APPROVE_PASS = new BaseAction(BillMessages.INSTANCE.action_approve_pass());
	
	public static BaseAction ACTION_APPROVE_NOPASS = new BaseAction(BillMessages.INSTANCE.action_approve_nopass());
	
	public static BaseAction QUERY_ACTION = MyActionFactory.createQueryAction();
	public static BaseAction NEW_ACTION = MyActionFactory.createNewAction();
	public static BaseAction MODIFY_ACTION = MyActionFactory.createModifyAction();
	public static BaseAction DELETE_ACTION = MyActionFactory.createDeleteAction();
	public static BaseAction SAVE_ACTION = MyActionFactory.createSaveAction();
	public static BaseAction CANCEL_ACTION = MyActionFactory.createCancelAction();
	
	public void onBillList(){
		BaseAction[] enableActions = {ACTION_NEW_REF,QUERY_ACTION,NEW_ACTION,MODIFY_ACTION,DELETE_ACTION,ACTION_APPROVE_PASS,ACTION_APPROVE_NOPASS};
		BaseAction[] disableActions = {SAVE_ACTION,CANCEL_ACTION,ACTION_GOTO_LIST};
		enableActions(enableActions);
		disableActions(disableActions);
	}
	
	public void onBillCard(){
		BaseAction[] disableActions = {ACTION_NEW_REF,QUERY_ACTION,NEW_ACTION,MODIFY_ACTION,DELETE_ACTION,ACTION_APPROVE_PASS,ACTION_APPROVE_NOPASS};
		BaseAction[] enableActions = {SAVE_ACTION,CANCEL_ACTION,ACTION_GOTO_LIST};
		enableActions(enableActions);
		disableActions(disableActions);

	}
	
	private void enableActions(BaseAction[] actions){
		for (BaseAction baseAction : actions) {
			baseAction.setEnable(true);
		}
	}
	
	private void disableActions(BaseAction[] actions){
		for (BaseAction baseAction : actions) {
			baseAction.setEnable(false);
		}
	}
	
}
